package com.dcits.ftz.controller;

import com.dcits.annotation.ParamCheck;
import com.dcits.common.Result;
import com.dcits.ftz.dto.in.UserIn;
import com.dcits.ftz.dto.out.UserOut;
import com.dcits.ftz.service.DemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/demo")
@Api(tags = "用户管理") // 类标签
public class DemoController {
    @Resource
    private DemoService demoService;

    /**
     * 样例代码，提供包括Swagger的编写规范和基于大V校验的参数校验
     * <ul>
     *     <li>Swagger的编写包括查看类注解（@Api）、方法注解（@ApiOperation）、模型注解（@ApiModel和@ApiModelProperty）</li>
     *     <li>大V校验使用方式来源于神码的基础验证框架的逻辑剥离，</li>
     * </ul>
     *
     * @param userIn
     * @return
     */
    @ApiOperation(value = "查询用户详情", notes = "获取用户信息")
    @GetMapping("/info-xss-enable")
    @ParamCheck
    public Result<UserIn> infoXssEnable(UserIn userIn) {

        return Result.success(userIn);
    }

    @ApiOperation(value = "查询用户详情", notes = "获取用户信息")
    @GetMapping("/info-xss-ingore")
    @ParamCheck
    public Result<UserIn> infoXssIngore(UserIn userIn) {

        return Result.success(userIn);
    }

    @ApiOperation(value = "用户注册", notes = "用于测试框架，执行时正常返回和业务异常场景测试")
    @GetMapping("/register")
    @ParamCheck
    public Result<UserOut> register(UserIn userIn) {
        final UserOut register = demoService.register(userIn);

        return Result.success(register);
    }
}
